
import unittest

from Schedule.MonthGenerator import MonthGenerator

class MonthGeneratorTestCases(unittest.TestCase):
    def setUp(self):
        pass
    
    def tearDown(self):
        pass

    def IndexTest(self, callIndex, nicuIndex, stepDownIndex, clinicIndex):
        # make sure that each index is used for one call only and that each number between 0 index and max is given a call type
        compiled = callIndex[:]
        compiled.extend(nicuIndex)
        compiled.extend(stepDownIndex)
        compiled.extend(clinicIndex)
        compiled.sort()
        
        length = compiled[len(compiled)-1] + 1
        x = [0 for x in range(length)]
        for i in compiled:
            x[i] = x[i] + 1

        for i in range(length):
            self.assertEquals(x[i], 1)
            
        
    def test_May(self):
                
        ''' numberDays, firstDayOfMonth, weeklySchedule, dayCycle, holidaySchedule, debug = False '''
        [schedule,
         weekBoundary,
         callIndex, 
         nicuIndex, 
         stepDownIndex, 
         clinicIndex,
         weekendCallIndex,
         weekdayCallDays,
         fridayCallDays,
         weekendCallDays,
         holidayCallDays] = MonthGenerator.generate(5, 2011)
        
        self.IndexTest(callIndex, nicuIndex, stepDownIndex, clinicIndex)
                
        self.assertEquals(schedule, [1, 4, 4, 3, 3, 3, 1, 1, 4, 4, 3, 3, 3, 1, 1, 4, 4, 3, 3, 3, 1, 1, 4, 4, 3, 3, 3, 1, 1, 1, 4])
        self.assertEquals(schedule[:7], [1, 4, 4, 3, 3, 3, 1])
        #self.assertEquals(daysInMonth, 31)
        self.assertEquals(weekBoundary, [19, 38, 57, 76])
        self.assertEquals(callIndex, [0, 1, 5, 9, 12, 15, 18, 19, 20, 24, 28, 31, 34, 37, 38, 39, 43, 47, 50, 53, 56, 57, 58, 62, 66, 69, 72, 75, 76, 77, 78])
        self.assertEquals(nicuIndex, [2, 6, 10, 13, 16, 21, 25, 29, 32, 35, 40, 44, 48, 51, 54, 59, 63, 67, 70, 73, 79])
        self.assertEquals(stepDownIndex, [3, 7, 11, 14, 17, 22, 26, 30, 33, 36, 41, 45, 49, 52, 55, 60, 64, 68, 71, 74, 80])
        self.assertEquals(clinicIndex, [4, 8, 23, 27, 42, 46, 61, 65, 81])
        self.assertEquals(weekendCallIndex, [0, 15, 18, 19, 34, 37, 38, 53, 56, 57, 72, 75, 76, 77])
        self.assertEquals(weekdayCallDays, [1, 2, 3, 4, 8, 9, 10, 11, 15, 16, 17, 18, 22, 23, 24, 25, 29, 30])
        self.assertEquals(fridayCallDays, [5, 12, 19, 26])
        self.assertEquals(weekendCallDays, [0, 6, 7, 13, 14, 20, 21, 27, 28])
        self.assertEquals(holidayCallDays, [29])

    def test_June(self):
                
        ''' numberDays, firstDayOfMonth, weeklySchedule, dayCycle, holidaySchedule, debug = False '''
        [schedule, 
         weekBoundary,
         callIndex, 
         nicuIndex, 
         stepDownIndex, 
         clinicIndex,
         weekendCallIndex,
         weekdayCallDays,
         fridayCallDays,
         weekendCallDays,
         holidayCallDays] = MonthGenerator.generate(6, 2011)
        
        self.IndexTest(callIndex, nicuIndex, stepDownIndex, clinicIndex)
                
        self.assertEquals(schedule, [3, 3, 3, 1, 1, 4, 4, 3, 3, 3, 1, 1, 4, 4, 3, 3, 3, 1, 1, 4, 4, 3, 3, 3, 1, 1, 4, 4, 3, 3])
        self.assertEquals(schedule[:7], [3, 3, 3, 1, 1, 4, 4])
        #self.assertEquals(daysInMonth, 30)
        self.assertEquals(weekBoundary, [10, 29, 48, 67])
        self.assertEquals(callIndex, [0, 3, 6, 9, 10, 11, 15, 19, 22, 25, 28, 29, 30, 34, 38, 41, 44, 47, 48, 49, 53, 57, 60, 63, 66, 67, 68, 72, 76, 79])
        self.assertEquals(nicuIndex, [1, 4, 7, 12, 16, 20, 23, 26, 31, 35, 39, 42, 45, 50, 54, 58, 61, 64, 69, 73, 77, 80])
        self.assertEquals(stepDownIndex, [2, 5, 8, 13, 17, 21, 24, 27, 32, 36, 40, 43, 46, 51, 55, 59, 62, 65, 70, 74, 78, 81])
        self.assertEquals(clinicIndex, [14, 18, 33, 37, 52, 56, 71, 75])
        self.assertEquals(weekendCallIndex, [6, 9, 10, 25, 28, 29, 44, 47, 48, 63, 66, 67])
        self.assertEquals(weekdayCallDays, [0, 1, 5, 6, 7, 8, 12, 13, 14, 15, 19, 20, 21, 22, 26, 27, 28, 29])
        self.assertEquals(fridayCallDays, [2, 9, 16, 23])
        self.assertEquals(weekendCallDays, [3, 4, 10, 11, 17, 18, 24, 25])
        self.assertEquals(holidayCallDays, [])

if __name__ == '__main__':
    unittest.main()
    